package NewCoder;

public class BM7 {
    public ListNode EntryNodeOfLoop(ListNode pHead) {
        if(pHead==null) return null;
        ListNode slow=pHead;
        ListNode fast=pHead;
        while(fast!=null && fast.next!=null){
            slow=slow.next;
            fast=fast.next.next;
            if(slow==fast){
                fast=pHead;
                while(slow!=fast){
                    fast=fast.next;
                    slow=slow.next;
                }
                return slow;

            }
        }
        return null;
    }
}
